package com.yanqu.road.entity.activity.hsisland.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.hsisland.HsIslandPosition;
import com.yanqu.road.entity.activity.hsisland.enums.HsIslandYnFlagEnum;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_c_activity_hs_island_event_data")
public class HsIslandEventData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "分组ID", select = true, update = true)
    private int groupId;

    @FieldTypeAnnotation(desc = "商会ID", select = true, update = true)
    private String unionId;

    @FieldTypeAnnotation(desc = "层ID", select = true, update = true)
    private int floorId;

    @FieldTypeAnnotation(desc = "岛ID", select = true, update = true)
    private int islandId;

    @FieldTypeAnnotation(desc = "玩家", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "事件唯一ID", select = true, update = true)
    private int eventUnId;

    @FieldTypeAnnotation(desc = "事件ID")
    private int eventId;

    @FieldTypeAnnotation(desc = "事件所在的坐标")
    private List<HsIslandPosition> positions = new ArrayList<>();

    @FieldTypeAnnotation(desc = "是否完结，0：否，1：是")
    private int finishFlag = 0;

    @FieldTypeAnnotation(desc = "奖励是否领取，0：否，1：是")
    private int rewardFlag = 0;

    @FieldTypeAnnotation(desc = "遗迹藏宝奖励")
    private Map<Integer, HsIslandReceiveRelicRewardData> receiveRelicRewardMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "PVE怪数据")
    private HsIslandMonsterData monsterData = null;

    @FieldTypeAnnotation(desc = "打死PVE怪的玩家ID")
    private long monsterWinUserId = 0;

    @FieldTypeAnnotation(desc = "2选1配置ID")
    private int chooseConfigId = 0;

    @FieldTypeAnnotation(desc = "魂师连战-对方商会ID")
    private String pvpUnionId = "";

    @FieldTypeAnnotation(desc = "魂师连战-对方玩家ID")
    private List<Long> pvpUserIds = new ArrayList<>();

    @FieldTypeAnnotation(desc = "buff id")
    private int buffId = 0;

    @FieldTypeAnnotation(desc = "宝库宝箱ID")
    private int boxId = 0;

    @FieldTypeAnnotation(desc = "圣柱馈赠配置ID")
    private int giftConfigId = 0;

    @FieldTypeAnnotation(desc = "是否删除，0：否，1：是")
    private int delFlag = 0;

    @FieldTypeAnnotation(desc = "生效的BUFF")
    private Set<Integer> buffIds = new ConcurrentHashSet<>();

    @FieldTypeAnnotation(desc = "是否是明灯开启的事件，0：否，1：是")
    private int lightFlag;

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public HsIslandEventData() {
    }

    public HsIslandEventData(int activityId, int groupId, String unionId, int floorId, int islandId, long userId, int eventUnId, int eventId, int lightFlag) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.unionId = unionId;
        this.floorId = floorId;
        this.islandId = islandId;
        this.userId = userId;
        this.eventUnId = eventUnId;
        this.eventId = eventId;
        this.lightFlag = lightFlag;
        this.createTime = System.currentTimeMillis();
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getGroupId() {
        return groupId;
    }
    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setOp(DataStatus.Update);
        }
    }

    public String getUnionId() {
        return unionId;
    }
    public void setUnionId(String unionId) {
        if (unionId == null){
            return;
        }
        if (this.unionId == null || !this.unionId.equals(unionId)) {
            this.unionId = unionId;
            setOp(DataStatus.Update);
        }
    }

    public int getFloorId() {
        return floorId;
    }
    public void setFloorId(int floorId) {
        if (this.floorId != floorId) {
            this.floorId = floorId;
            setOp(DataStatus.Update);
        }
    }

    public int getIslandId() {
        return islandId;
    }
    public void setIslandId(int islandId) {
        if (this.islandId != islandId) {
            this.islandId = islandId;
            setOp(DataStatus.Update);
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public int getEventUnId() {
        return eventUnId;
    }

    public void setEventUnId(int eventUnId) {
        if (this.eventUnId != eventUnId) {
            this.eventUnId = eventUnId;
            setOp(DataStatus.Update);
        }
    }

    public int getEventId() {
        return eventId;
    }
    public void setEventId(int eventId) {
        if (this.eventId != eventId) {
            this.eventId = eventId;
            setOp(DataStatus.Update);
        }
    }

    public List<HsIslandPosition> getPositions() {
        return positions;
    }

    public void setPositions(List<HsIslandPosition> positions) {
        if (null == positions){
            return;
        }
        if (this.positions == null || !this.positions.equals(positions)) {
            this.positions = positions;
            setOp(DataStatus.Update);
        }
    }

    public void addPosition(int x, int y) {
        HsIslandPosition position = new HsIslandPosition(x, y);
        this.addPosition(position);
    }

    public void addPosition(HsIslandPosition position) {
        this.positions.add(position);
        setOp(DataStatus.Update);
    }

    public int getFinishFlag() {
        return finishFlag;
    }

    public void setFinishFlag(int finishFlag) {
        if (this.finishFlag != finishFlag) {
            this.finishFlag = finishFlag;
            setOp(DataStatus.Update);
        }
    }

    public int getRewardFlag() {
        return rewardFlag;
    }

    public void setRewardFlag(int rewardFlag) {
        if (this.rewardFlag != rewardFlag) {
            this.rewardFlag = rewardFlag;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, HsIslandReceiveRelicRewardData> getReceiveRelicRewardMap() {
        return receiveRelicRewardMap;
    }

    public HsIslandReceiveRelicRewardData getReceiveRelicReward(int relicConfigId) {
        return receiveRelicRewardMap.get(relicConfigId);
    }

    public void setReceiveRelicRewardMap(Map<Integer, HsIslandReceiveRelicRewardData> receiveRelicRewardMap) {
        if (null == receiveRelicRewardMap){
            return;
        }
        if (this.receiveRelicRewardMap == null || !this.receiveRelicRewardMap.equals(receiveRelicRewardMap)) {
            this.receiveRelicRewardMap = receiveRelicRewardMap;
            setOp(DataStatus.Update);
        }
    }

    public void putReceiveRelicReward(HsIslandReceiveRelicRewardData data) {
        this.receiveRelicRewardMap.put(data.getRelicConfigId(), data);
        setOp(DataStatus.Update);
    }

    public HsIslandMonsterData getMonsterData() {
        return monsterData;
    }
    public void setMonsterData(HsIslandMonsterData monsterData) {
        if (null == monsterData){
            return;
        }
        if (this.monsterData == null || !this.monsterData.equals(monsterData)) {
            this.monsterData = monsterData;
            setOp(DataStatus.Update);
        }
    }

    public long getMonsterWinUserId() {
        return monsterWinUserId;
    }

    public void setMonsterWinUserId(long monsterWinUserId) {
        if (this.monsterWinUserId != monsterWinUserId) {
            this.monsterWinUserId = monsterWinUserId;
            setOp(DataStatus.Update);
        }
    }

    public int getChooseConfigId() {
        return chooseConfigId;
    }

    public void setChooseConfigId(int chooseConfigId) {
        if (this.chooseConfigId != chooseConfigId) {
            this.chooseConfigId = chooseConfigId;
            setOp(DataStatus.Update);
        }
    }

    public String getPvpUnionId() {
        return pvpUnionId;
    }

    public void setPvpUnionId(String pvpUnionId) {
        if (pvpUnionId == null){
            return;
        }
        if (this.pvpUnionId == null || !this.pvpUnionId.equals(pvpUnionId)) {
            this.pvpUnionId = pvpUnionId;
            setOp(DataStatus.Update);
        }
    }

    public List<Long> getPvpUserIds() {
        return pvpUserIds;
    }

    public void setPvpUserIds(List<Long> pvpUserIds) {
        if (null == pvpUserIds){
            return;
        }
        if (this.pvpUserIds == null || !this.pvpUserIds.equals(pvpUserIds)) {
            this.pvpUserIds = pvpUserIds;
            setOp(DataStatus.Update);
        }
    }

    public int getBuffId() {
        return buffId;
    }

    public void setBuffId(int buffId) {
        if (this.buffId != buffId) {
            this.buffId = buffId;
            setOp(DataStatus.Update);
        }
    }

    public int getBoxId() {
        return boxId;
    }

    public void setBoxId(int boxId) {
        if (this.boxId != boxId) {
            this.boxId = boxId;
            setOp(DataStatus.Update);
        }
    }

    public int getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(int delFlag) {
        if (this.delFlag != delFlag) {
            this.delFlag = delFlag;
            setOp(DataStatus.Update);
        }
    }

    public long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
        if (this.createTime != createTime) {
            this.createTime = createTime;
            setOp(DataStatus.Update);
        }
    }

    public int getGiftConfigId() {
        return giftConfigId;
    }

    public void setGiftConfigId(int giftConfigId) {
        if (this.giftConfigId != giftConfigId) {
            this.giftConfigId = giftConfigId;
            setOp(DataStatus.Update);
        }
    }

    public Set<Integer> getBuffIds() {
        return buffIds;
    }

    public void setBuffIds(Set<Integer> buffIds) {
        if (null == buffIds){
            return;
        }
        if (this.buffIds == null || !this.buffIds.equals(buffIds)) {
            this.buffIds = buffIds;
            setOp(DataStatus.Update);
        }
    }

    public void addBuffId(int buffId) {
        this.buffIds.add(buffId);
        setOp(DataStatus.Update);
    }

    public int getLightFlag() {
        return lightFlag;
    }

    public void setLightFlag(int lightFlag) {
        if (this.lightFlag != lightFlag) {
            this.lightFlag = lightFlag;
            setOp(DataStatus.Update);
        }
    }

    /**
     * 获取未选的宝箱奖励数量
     * @return
     */
    public int getNotSelectRelicReward() {
        int num = 0;
        for (HsIslandReceiveRelicRewardData rewardData : this.receiveRelicRewardMap.values()) {
            if (rewardData.getReceiveFlag() == HsIslandYnFlagEnum.NOT.getType()) {
                num++;
            }
        }
        return num;
    }
}
